package com.mashibing.juc.c_026_01_ThreadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Executors.newSingleThreadExecutor();单线程线程池
 * 单线程线程池存在的意义：
 *  1.线程队列
 *  2.线程生命周期维护
 * @author: Yuanzt
 * @Date: 2021/4/2
 */
public class T07_SigleThreadPool {

    public static void main(String[] args) {
        //这个方式创建的线程是单例的，Executors-线程池的工厂
        ExecutorService service = Executors.newSingleThreadExecutor();
        for (int i = 0; i < 5; i++) {
            final int j = i;
            service.execute(()->{
                System.out.println(j + " " + Thread.currentThread().getName());
            });
        }
    }
}
